home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libio / gen-params < prev    next >
Text File  |  1994-10-19  |  20KB  |  630 lines

  1. #!/bin/sh
  2. # Copyright (C) 1992, 1993, 1994 Free Software Foundation
  3. # This file is part of the GNU IO Library.  This library is free
  4. # software; you can redistribute it and/or modify it under the
  5. # terms of the GNU General Public License as published by the
  6. # Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. # This library is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with GNU CC; see the file COPYING.  If not, write to
  14. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  15.  
  16. #    Written by Per Bothner (bothner@cygnus.com)
  17.  
  18. # This is a shell-script that figures out various things about a
  19. # system, and writes (to stdout) a C-style include files with
  20. # suitable definitions, including all the standard Posix types.
  21. # It works by compiling various test programs -- some are run through
  22. # the C pre-processor, and the output examined.
  23. # The test programs are only compiled, not executed, so the script
  24. # should even if you're cross-compiling.
  25. # It uses $CC (which defaults to cc) to compile C programs (extension .c),
  26. # and $CXX (which defaults to gcc) to compile C++ programs (extension .C).
  27. # The shell-script is written for libg++.a.
  28.  
  29. # Usage: gen-params [NAME1=name1 ...]
  30. # - where an assignment (such as size_t="unsigned int" means to
  31. # use that value, instead of trying to figure it out.
  32.  
  33. # Uncomment following line for debugging
  34. # set -x
  35.  
  36. SED=sed
  37.  
  38. # Evaluate the arguments (which should be assignments):
  39. for arg in "$@"; do
  40.   # Quote arg (i.e. FOO=bar => FOO='bar'), then eval it.
  41.   eval `echo "$arg" | ${SED} -e "s|^\(.*\)=\(.*\)|\1='\2'|"`
  42. done
  43.  
  44. macro_prefix=${macro_prefix-"_G_"}
  45. rootdir=`pwd`/..
  46. gccdir=${gccdir-${rootdir}/gcc}
  47. binutilsdir=${binutilsdir-${rootdir}/binutils}
  48. CC=${CC-`if [ -f ${gccdir}/xgcc ] ; \
  49.     then echo ${gccdir}/xgcc -B${gccdir}/ ; \
  50.     else echo cc ; fi`}
  51. CXX=${CXX-`if [ -f ${gccdir}/xgcc ] ; \
  52.     then echo ${gccdir}/xgcc -B${gccdir}/ ; \
  53.     else echo gcc ; fi`}
  54. CPP=${CPP-`echo ${CC} -E`}
  55. CONFIG_NM=${CONFIG_NM-`if [ -f ${binutilsdir}/nm.new ] ; \
  56.     then echo ${binutilsdir}/nm.new ; \
  57.     else echo nm ; fi`}
  58.  
  59. cat <<!EOF!
  60. /* AUTOMATICALLY GENERATED; DO NOT EDIT! */ 
  61. #ifndef ${macro_prefix}config_h
  62. #define ${macro_prefix}config_h
  63. !EOF!
  64.  
  65. if [ x"${LIB_VERSION}" != "x" ] ; then
  66.   echo "#define ${macro_prefix}LIB_VERSION" '"'${LIB_VERSION}'"'
  67. fi
  68.  
  69. # This program is used to test if the compiler prepends '_' before identifiers.
  70. # It is also used to check the g++ uses '$' or '.' various places.
  71.  
  72. if test -z "${NAMES_HAVE_UNDERSCORE}" -o -z "${DOLLAR_IN_LABEL}" \
  73.     -o -z "${VTABLE_LABEL_PREFIX}"; then
  74.   cat >dummy.C <<!EOF!
  75.   struct filebuf {
  76.       virtual int foo();
  77.   };
  78.   filebuf ff;
  79.   extern "C" int FUNC(int);
  80.   int FUNC(int i) { return i+10; }
  81. !EOF!
  82.  
  83.   if ${CXX} -O -c dummy.C ; then
  84.     if test -z "${NAMES_HAVE_UNDERSCORE}" ; then
  85.       if test "`${CONFIG_NM} dummy.o | grep _FUNC`" != ""; then
  86.         NAMES_HAVE_UNDERSCORE=1
  87.       elif test "`${CONFIG_NM} dummy.o | grep FUNC`" != ""; then
  88.         NAMES_HAVE_UNDERSCORE=0
  89.       else
  90.         echo "${CONFIG_NM} failed to find FUNC in dummy.o!" 1>&2; exit -1;
  91.       fi
  92.     fi
  93.     echo "#define ${macro_prefix}NAMES_HAVE_UNDERSCORE ${NAMES_HAVE_UNDERSCORE}"
  94.  
  95.     if test -z "${VTABLE_LABEL_PREFIX}" ; then
  96.       # Determine how virtual function tables are named.  This is fragile,
  97.       # because different nm's produce output in different formats.
  98.       ${CONFIG_NM} dummy.o >TMP
  99.       # First we look for a pattern that matches historical output from g++.
  100.       # We surround the actual label name by <> to separate it from
  101.       # other nm junk. 
  102.       ${SED} -n -e 's/_*vt[$_.]7*filebuf/<&>/p' <TMP >dummy.out
  103.       # For paranoia's sake (e.g. if we're using some other C++ compiler)
  104.       # we try a more general pattern, and append the result.
  105.       grep -v foo <TMP \
  106.     | ${SED} -n -e 's/[a-zA-Z0-9_.$]*filebuf[a-zA-Z0-9_.$]*/<&>/p' \
  107.     >>dummy.out
  108.       # Now we get rid of the <>, and any other junk on the nm output line.
  109.       # (We get rid of <filebuf> in case nm included debugging output for
  110.       # class filebuf itself.)  Finally, we select the first line of
  111.       # the result, and hope that's what we wanted!
  112.       vtab_name=`${SED} -n -e '/<filebuf>/d' -e 's/^.*<\(.*\)>.*$/\1/p' \
  113.         <dummy.out | ${SED} -n -e '1p'`
  114.       case "${vtab_name}" in
  115.         *7filebuf) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 1" ;;
  116.         *) echo "#define ${macro_prefix}VTABLE_LABEL_HAS_LENGTH 0" ;;
  117.       esac
  118.       VTABLE_LABEL_PREFIX=`echo $vtab_name | sed -e 's/7*filebuf//'`
  119.     fi
  120.     echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX" '"'"${VTABLE_LABEL_PREFIX}"'"'
  121.     if [ "${VTABLE_LABEL_PREFIX}" = "__vt_" -o \
  122.         "${VTABLE_LABEL_PREFIX}" = "___vt_" ] ; then
  123.       echo "#define ${macro_prefix}USING_THUNKS"
  124.     fi
  125.  
  126.     # VTABLE_LABEL_PREFIX_ID is the same as VTABLE_LABEL_PREFIX,
  127.     # but the former is a C identifier, while the latter is a quoted
  128.     # st
  129.     if [ -z ""`echo ${VTABLE_LABEL_PREFIX} | sed -e 's/[a-zA-Z0-9_]//g'` ] ; then
  130.       if [ "${NAMES_HAVE_UNDERSCORE}" = "1" ] ; then
  131.     VTABLE_LABEL_PREFIX=`echo ${VTABLE_LABEL_PREFIX} | sed -e 's/^_//'`
  132.       fi
  133.       echo "#define ${macro_prefix}VTABLE_LABEL_PREFIX_ID ${VTABLE_LABEL_PREFIX}"
  134.     fi
  135.  
  136. #    if test -n "${DOLLAR_IN_LABEL}" ; then
  137. #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL ${DOLLAR_IN_LABEL}"
  138. #    elif test "`${CONFIG_NM} dummy.o | grep 'vt[$$]7filebuf'`" != ""; then
  139. #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 1"
  140. #    elif test "`${CONFIG_NM} dummy.o | grep 'vt[.]7filebuf'`" != ""; then
  141. #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
  142. #    elif test "`${CONFIG_NM} dummy.o | grep 'vtbl__7filebuf'`" != ""; then
  143. #      echo "#define ${macro_prefix}DOLLAR_IN_LABEL 0"
  144. #    else
  145. #      echo "gen-params: ${CONFIG_NM} failed to find vt[.\$]filebuf in dummy.o!" 1>&2; exit 1
  146. #    fi
  147.   else
  148.     # The compile failed for some reason (no C++?)
  149.     echo "gen-params: could not compile dummy.C with ${CXX}" 1>&2; exit 1;
  150.   fi
  151. fi
  152.  
  153. # A little test program to check if struct stat has st_blksize.
  154. cat >dummy.c <<!EOF!
  155. #include <sys/types.h>
  156. #include <sys/stat.h>
  157. int BLKSIZE(struct stat *st)
  158. {
  159.     return st->st_blksize;
  160. }
  161. !EOF!
  162.  
  163. if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  164.   echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 1"
  165. else
  166.   echo "#define ${macro_prefix}HAVE_ST_BLKSIZE 0"
  167. fi
  168.  
  169. # Next, generate definitions for the standard types (such as mode_t)
  170. # compatible with those in the standard C header files.
  171. # It works by a dummy program through the C pre-processor, and then
  172. # using sed to search for typedefs in the output.
  173.  
  174. for hdr in wchar wctype; do
  175.   eval $hdr=0
  176.   cat >dummy.c <<EOF
  177. #include <${hdr}.h>
  178. EOF
  179.   if ${CPP} dummy.c >/dev/null 2>&1 ; then eval $hdr=1; fi
  180. done
  181.  
  182. cat >dummy.c <<!EOF!
  183. #include <sys/types.h>
  184. #include <stddef.h>
  185. #include <stdarg.h>
  186. #include <stdio.h>
  187. #include <time.h>
  188. #include <signal.h>
  189. #ifdef __STDC__
  190. #include <limits.h>
  191. #endif
  192. #if WCHAR == 1
  193. #include <wchar.h>
  194. #endif
  195. #if WCTYPE == 1
  196. #include <wctype.h>
  197. #endif
  198. #ifdef size_t
  199. typedef size_t Xsize_t;
  200. #elif defined(__SIZE_TYPE__)
  201. typedef __SIZE_TYPE__ Xsize_t;
  202. #endif
  203. #ifdef ptrdiff_t
  204. typedef ptrdiff_t Xptrdiff_t;
  205. #elif defined(__PTRDIFF_TYPE__)
  206. typedef __PTRDIFF_TYPE__ Xptrdiff_t;
  207. #endif
  208. #ifdef wchar_t
  209. typedef wchar_t Xwchar_t;
  210. #elif defined(__WCHAR_TYPE__)
  211. typedef __WCHAR_TYPE__ Xwchar_t;
  212. #endif
  213. #ifdef va_list
  214. typedef va_list XXXva_list;
  215. #endif
  216. #ifdef BUFSIZ
  217. long XBUFSIZ=BUFSIZ;
  218. #endif
  219. #ifdef FOPEN_MAX
  220. long XFOPEN_MAX=FOPEN_MAX;
  221. #endif
  222. #ifdef FILENAME_MAX
  223. long XFILENAME_MAX=FILENAME_MAX;
  224. #endif
  225. #ifdef SHRT_MAX
  226. long XSHRT_MAX=SHRT_MAX;
  227. #endif
  228. #ifdef INT_MAX
  229. long XINT_MAX=INT_MAX;
  230. #endif
  231. #ifdef LONG_MAX
  232. long XLONG_MAX=LONG_MAX;
  233. #endif
  234. #ifdef LONG_LONG_MAX
  235. long XLONG_LONG_MAX=LONG_LONG_MAX;
  236. #endif
  237. !EOF!
  238.  
  239. if ${CPP} dummy.c -DWCHAR=$wchar -DWCTYPE=$wctype >TMP ; then true
  240. else
  241.   echo "gen-params: could not invoke ${CPP} on dummy.c" 1>&2 ; exit 1
  242. fi
  243. tr '    ' ' ' <TMP >dummy.out
  244.  
  245. for TYPE in dev_t clock_t fpos_t gid_t ino_t mode_t nlink_t off_t pid_t ptrdiff_t sigset_t size_t ssize_t time_t uid_t va_list wchar_t wint_t int8_t uint8_t int16_t uint16_t int32_t uint_32_t int64_t uint64_t; do
  246.     IMPORTED=`eval 'echo $'"$TYPE"`
  247.     if [ -n "${IMPORTED}" ] ; then
  248.     eval "$TYPE='$IMPORTED"
  249.     else
  250.     # Search dummy.out for a typedef for $TYPE, and write it out
  251.     # to TMP in #define syntax.
  252.     rm -f TMP
  253.     ${SED} -n -e "s|.*typedef  *\(.*\) X*$TYPE *;.*|\1|w TMP" \
  254.       <dummy.out>/dev/null
  255.     # Now select the first definition.
  256.         if [ -s TMP ]; then
  257.         # VALUE is now the typedef'd definition of $TYPE.
  258.             eval "VALUE='`${SED} -e 's| *$||' -e '2,$d' <TMP`'"
  259.         # Unless VALUE contains a blank, look for a typedef for it
  260.         # in turn (this could be a loop, but that would be over-kill).
  261.         if echo $VALUE | grep " " >/dev/null ; then true
  262.         else
  263.         rm -f TMP
  264.         ${SED} -n -e "s|.*typedef[     ][     ]*\(.*[^a-zA-Z0-9_]\)${VALUE}[     ]*;.*|\1|w TMP" <dummy.out>/dev/null
  265.         if [ -s TMP ]; then
  266.             eval "VALUE='`${SED} -e '2,$d' -e 's|[     ]*$||' <TMP`'"
  267.         fi
  268.         fi
  269.         eval "$TYPE='$VALUE'"
  270.     fi
  271.     fi
  272. done
  273.  
  274. cat <<!EOF!
  275. typedef ${clock_t-int /* default */} ${macro_prefix}clock_t;
  276. typedef ${dev_t-int /* default */} ${macro_prefix}dev_t;
  277. typedef ${fpos_t-long /* default */} ${macro_prefix}fpos_t;
  278. typedef ${gid_t-int /* default */} ${macro_prefix}gid_t;
  279. typedef ${ino_t-int /* default */} ${macro_prefix}ino_t;
  280. typedef ${mode_t-int /* default */} ${macro_prefix}mode_t;
  281. typedef ${nlink_t-int /* default */} ${macro_prefix}nlink_t;
  282. typedef ${off_t-long /* default */} ${macro_prefix}off_t;
  283. typedef ${pid_t-int /* default */} ${macro_prefix}pid_t;
  284. #ifndef __PTRDIFF_TYPE__
  285. #define __PTRDIFF_TYPE__ ${ptrdiff_t-long int /* default */}
  286. #endif
  287. typedef __PTRDIFF_TYPE__ ${macro_prefix}ptrdiff_t;
  288. typedef ${sigset_t-int /* default */} ${macro_prefix}sigset_t;
  289. #ifndef __SIZE_TYPE__
  290. #define __SIZE_TYPE__ ${size_t-unsigned long /* default */}
  291. #endif
  292. typedef __SIZE_TYPE__ ${macro_prefix}size_t;
  293. typedef ${time_t-int /* default */} ${macro_prefix}time_t;
  294. typedef ${uid_t-int /* default */} ${macro_prefix}uid_t;
  295. #ifndef __WCHAR_TYPE__
  296. #define __WCHAR_TYPE__ ${wchar_t-int /* default */}
  297. #endif
  298. typedef __WCHAR_TYPE__ ${macro_prefix}wchar_t;
  299. !EOF!
  300.  
  301.  
  302. # ssize_t is the signed version of size_t
  303. if [ -n "${ssize_t}" ] ; then
  304.     echo "typedef ${ssize_t} ${macro_prefix}ssize_t;"
  305. elif [ -z "${size_t}" ] ; then
  306.     echo "typedef long ${macro_prefix}ssize_t;"
  307. else
  308.     # Remove "unsigned" from ${size_t} to get ${ssize_t}.
  309.     tmp="`echo ${size_t} | ${SED} -e 's|unsigned||g' -e 's|  | |g'`"
  310.     if [ -z "$tmp" ] ; then
  311.     tmp=int
  312.     else
  313.     # check $tmp doesn't conflict with <unistd.h>
  314.     echo "#include <unistd.h>
  315.     extern $tmp read();" >dummy.c
  316.     ${CC} -c dummy.c >/dev/null 2>&1 || tmp=int
  317.     fi
  318.     echo "typedef $tmp /* default */ ${macro_prefix}ssize_t;"
  319. fi
  320.  
  321. # wint_t is often the integral type to which wchar_t promotes.
  322. if [ -n "${wint_t}" ] ; then
  323.   echo "typedef ${wint_t} ${macro_prefix}wint_t;"
  324. else
  325.   for TYPE in int 'unsigned int' 'long int' 'long unsigned int'; do
  326.     cat >dummy.C <<!EOF!
  327. #ifndef __WCHAR_TYPE__
  328. #define __WCHAR_TYPE__ ${wchar_t-int /* default */}
  329. #endif
  330. typedef __WCHAR_TYPE__ ${macro_prefix}wchar_t;
  331. void foo ($TYPE);
  332. void foo (double);
  333. void bar (${macro_prefix}wchar_t w)
  334. {
  335.   foo (w);
  336. }
  337. !EOF!
  338.     if ${CXX} -c dummy.C >/dev/null 2>&1 ; then  
  339.       echo "typedef $TYPE /* default */ ${macro_prefix}wint_t;"
  340.       break
  341.     fi
  342.   done
  343. fi
  344.  
  345. # va_list can cause problems (e.g. some systems have va_list as a struct).
  346. # Check to see if ${va_list-char*} really is compatible with stdarg.h.
  347. cat >dummy.C <<!EOF!
  348. #define X_va_list ${va_list-char* /* default */}
  349. extern long foo(X_va_list ap); /* Check that X_va_list compiles on its own */
  350. extern "C" {
  351. #include <stdarg.h>
  352. }
  353. long foo(X_va_list ap) { return va_arg(ap, long); }
  354. long bar(int i, ...)
  355. { va_list ap; long j; va_start(ap, i); j = foo(ap); va_end(ap); return j; }
  356. !EOF!
  357. if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
  358.   # Ok: We have something that works.
  359.   echo "typedef ${va_list-char* /* default */} ${macro_prefix}va_list;"
  360. else
  361.   # No, it breaks.  Indicate that <stdarg.h> must be included.
  362.   echo "#define ${macro_prefix}NEED_STDARG_H
  363. #define ${macro_prefix}va_list va_list"
  364. fi
  365.  
  366. cat >dummy.c <<!EOF!
  367. #include <signal.h>
  368. extern int (*signal())();
  369. extern int dummy (int);
  370. main()
  371. {
  372.     int (*oldsig)(int) = signal (1, dummy);
  373.     (void) signal (2, oldsig);
  374.     return 0;
  375. }
  376. !EOF!
  377. if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  378.   echo "#define ${macro_prefix}signal_return_type int"
  379. else
  380.   echo "#define ${macro_prefix}signal_return_type void"
  381. fi
  382.  
  383. # check sprintf return type
  384.  
  385. cat >dummy.c <<!EOF!
  386. #include <stdio.h>
  387. extern int sprintf(); char buf[100];
  388. int main() { return sprintf(buf, "%d", 34); }
  389. !EOF!
  390. if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  391.   echo "#define ${macro_prefix}sprintf_return_type int"
  392. else
  393.   echo "#define ${macro_prefix}sprintf_return_type char*"
  394. fi
  395.  
  396. # Look for some standard macros.
  397. for NAME in BUFSIZ FOPEN_MAX FILENAME_MAX NULL; do
  398.     IMPORTED=`eval 'echo $'"$NAME"`
  399.     if [ -n "${IMPORTED}" ] ; then
  400.     eval "$NAME='$IMPORTED /* specified */"
  401.     else
  402.     rm -f TMP
  403.     ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\(.*\);|\1|w TMP" \
  404.       <dummy.out>/dev/null
  405.     # Now select the first definition.
  406.     if [ -s TMP ]; then
  407.         eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
  408.     fi
  409.     fi
  410. done
  411.  
  412. # These macros must be numerical constants; strip any trailing 'L's.
  413. for NAME in SHRT_MAX INT_MAX LONG_MAX LONG_LONG_MAX; do
  414.     IMPORTED=`eval 'echo $'"$NAME"`
  415.     if [ -n "${IMPORTED}" ] ; then
  416.     eval "$NAME='$IMPORTED /* specified */"
  417.     else
  418.     rm -f TMP
  419.     ${SED} -n -e 's| *;|;|g' -e "s|long X${NAME}= *\([0-9]*\)L* *;|\1|w TMP" \
  420.       <dummy.out>/dev/null
  421.     # Now select the first definition.
  422.     if [ -s TMP ]; then
  423.         eval "$NAME='"`${SED} -e '2,$d' <TMP`"'"
  424.     fi
  425.     fi
  426. done
  427.  
  428. # Figure out integral type sizes.
  429.  
  430. default_int16=
  431. default_int32=
  432. default_int64=
  433. INT16=32767
  434. INT32=2147483647
  435. INT64=9223372036854775807
  436.  
  437. if [ "${SHRT_MAX}" = $INT16 ] ; then
  438.   default_int16=short
  439.   if [ "${LONG_MAX}" = $INT32 ] ; then
  440.     default_int32=long
  441.     if [ "${LONG_LONG_MAX}" = $INT64 ] ; then
  442.       # Most Unices, DOS
  443.       default_int64="long long"
  444.     fi
  445.   elif [ "${INT_MAX}" = $INT32 ] ; then
  446.     default_int32=int
  447.     if [ "${LONG_MAX}" = $INT64 ] ; then
  448.       # Some 64-bit Unices, like OSF/1 on the Alpha
  449.       default_int64=long
  450.     fi
  451.   fi
  452. fi
  453.  
  454. if [ -n "${int64_t-${default_int64}}" ] ; then
  455.   int64_lines="#define HAVE_INT64
  456. typedef ${int64_t-${default_int64}} ${macro_prefix}int64_t;
  457. typedef ${uint64_t-unsigned ${default_int64}} ${macro_prefix}uint64_t;"
  458.   if [ "${default_int64}" = "long long" ] ; then
  459.     int64_lines="#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(_NO_LONGLONG)
  460. ${int64_lines}
  461. #endif"
  462.   fi
  463. fi
  464.  
  465. cat <<!EOF!
  466. #ifdef __STDC__
  467. typedef ${int8_t-signed char} ${macro_prefix}int8_t;
  468. #endif
  469. typedef ${uint8_t-unsigned char} ${macro_prefix}uint8_t;
  470. typedef ${int16_t-${default_int16-short}} ${macro_prefix}int16_t;
  471. typedef ${uint16_t-unsigned ${default_int16-short}} ${macro_prefix}uint16_t;
  472. typedef ${int32_t-${default_int32-int}} ${macro_prefix}int32_t;
  473. typedef ${uint32_t-unsigned ${default_int32-int}} ${macro_prefix}uint32_t;
  474. ${int64_lines}
  475. #define ${macro_prefix}BUFSIZ ${BUFSIZ-1024 /* default */}
  476. #define ${macro_prefix}FOPEN_MAX ${FOPEN_MAX-32 /* default */}
  477. #define ${macro_prefix}FILENAME_MAX ${FILENAME_MAX-1024 /* default */}
  478. #define ${macro_prefix}NULL ${NULL-0 /* default */}
  479. #if defined (__cplusplus) || defined (__STDC__)
  480. #define ${macro_prefix}ARGS(ARGLIST) ARGLIST
  481. #else
  482. #define ${macro_prefix}ARGS(ARGLIST) ()
  483. #endif
  484. #if !defined (__GNUG__) || defined (__STRICT_ANSI__)
  485. #define ${macro_prefix}NO_NRV
  486. #endif
  487. #if !defined (__GNUG__)
  488. #define _G_NO_EXTERN_TEMPLATES
  489. #endif
  490. !EOF!
  491.  
  492. rm -f dummy.c dummy.o
  493.  
  494. if test -n "${HAVE_ATEXIT}" ; then
  495.  echo "#define ${macro_prefix}HAVE_ATEXIT ${HAVE_ATEXIT}"
  496. else
  497.   cat >dummy.c <<!EOF!
  498. #include <stdlib.h>
  499. int main()
  500. {
  501.   atexit (0);
  502. }
  503. !EOF!
  504.   if ${CC} dummy.c >/dev/null 2>&1 ; then
  505.     echo "#define ${macro_prefix}HAVE_ATEXIT 1"
  506.   else
  507.     echo "#define ${macro_prefix}HAVE_ATEXIT 0"
  508.   fi
  509. fi
  510.  
  511.  
  512. # *** Check for presence of certain include files ***
  513.  
  514. # check for sys/resource.h
  515.  
  516. if test -n "${HAVE_SYS_RESOURCE}" ; then
  517.  echo "#define ${macro_prefix}HAVE_SYS_RESOURCE ${HAVE_SYS_RESOURCE}"
  518. else
  519.   cat >dummy.c <<!EOF!
  520. #include <sys/time.h>
  521. #include <sys/resource.h>
  522.   int main()
  523.   {
  524.     struct rusage res;
  525.     getrusage(RUSAGE_SELF, &res);
  526.     return (int)(res.ru_utime.tv_sec + (res.ru_utime.tv_usec / 1000000.0));
  527.   }
  528. !EOF!
  529.   # Note: We link because some systems have sys/resource, but not getrusage().
  530.   if ${CC} dummy.c >/dev/null 2>&1 ; then
  531.     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 1"
  532.   else
  533.     echo "#define ${macro_prefix}HAVE_SYS_RESOURCE 0"
  534.   fi
  535. fi
  536.  
  537. # check for sys/socket.h
  538.  
  539. if test -n "${HAVE_SYS_SOCKET}" ; then
  540.  echo "#define ${macro_prefix}HAVE_SYS_SOCKET ${HAVE_SYS_SOCKET}"
  541. else
  542.   echo '#include <sys/types.h>' >dummy.c
  543.   echo '#include <sys/socket.h>' >>dummy.c
  544.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  545.     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 1"
  546.   else
  547.     echo "#define ${macro_prefix}HAVE_SYS_SOCKET 0"
  548.   fi
  549. fi
  550.  
  551. # Check for a (Posix-compatible) sys/wait.h */
  552.  
  553. if test -n "${HAVE_SYS_WAIT}" ; then
  554.  echo "#define ${macro_prefix}HAVE_SYS_WAIT ${HAVE_SYS_WAIT}"
  555. else
  556.   cat >dummy.c <<!EOF!
  557. #include <sys/types.h>
  558. #include <sys/wait.h>
  559.   int f() { int i; wait(&i); return i; }
  560. !EOF!
  561.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  562.     echo "#define ${macro_prefix}HAVE_SYS_WAIT 1"
  563.   else
  564.     echo "#define ${macro_prefix}HAVE_SYS_WAIT 0"
  565.   fi
  566. fi
  567.  
  568. if test -n "${HAVE_UNISTD}" ; then
  569.  echo "#define ${macro_prefix}HAVE_UNISTD ${HAVE_UNISTD}"
  570. else
  571.   echo '#include <unistd.h>' >dummy.c
  572.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  573.     echo "#define ${macro_prefix}HAVE_UNISTD 1"
  574.   else
  575.     echo "#define ${macro_prefix}HAVE_UNISTD 0"
  576.   fi
  577. fi
  578.  
  579. if test -n "${HAVE_DIRENT}" ; then
  580.  echo "#define ${macro_prefix}HAVE_DIRENT ${HAVE_DIRENT}"
  581. else
  582.   echo '#include <sys/types.h>
  583. #include <dirent.h>' >dummy.c
  584.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  585.     echo "#define ${macro_prefix}HAVE_DIRENT 1"
  586.   else
  587.     echo "#define ${macro_prefix}HAVE_DIRENT 0"
  588.   fi
  589. fi
  590.  
  591. if test -n "${HAVE_CURSES}" ; then
  592.  echo "#define ${macro_prefix}HAVE_CURSES ${HAVE_CURSES}"
  593. else
  594.   echo '#include <curses.h>' >dummy.c
  595.   if ${CC} -c dummy.c >/dev/null 2>&1 ; then
  596.     echo "#define ${macro_prefix}HAVE_CURSES 1"
  597.   else
  598.     echo "#define ${macro_prefix}HAVE_CURSES 0"
  599.   fi
  600. fi
  601.  
  602. # There is no test for this at the moment; it is just set by the
  603. # configuration files.
  604. if test -n "${MATH_H_INLINES}" ; then
  605.   echo "#define ${macro_prefix}MATH_H_INLINES ${MATH_H_INLINES}"
  606. else
  607.   echo "#define ${macro_prefix}MATH_H_INLINES 0"
  608. fi
  609.  
  610. if test -n "${HAVE_BOOL}" ; then
  611.  echo "#define ${macro_prefix}HAVE_BOOL ${HAVE_BOOL}"
  612. else
  613.   echo 'bool i=true,j=false;' >dummy.C
  614.   if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
  615.     echo "#define ${macro_prefix}HAVE_BOOL 1"
  616.   else
  617.     echo "#define ${macro_prefix}HAVE_BOOL 0"
  618.   fi
  619. fi
  620.  
  621. # Uncomment the following line if you don't have working templates.
  622. # echo "#define ${macro_prefix}NO_TEMPLATES"
  623.  
  624. rm -f dummy.C dummy.o dummy.c dummy.out TMP core a.out
  625.  
  626. echo "#endif /* !${macro_prefix}config_h */"
  627.